#include "scene.h"
#include<stdlib.h>

scene::scene(QObject *parent) : QGraphicsScene(parent)
{
  int i=0;   //i为坐标
  for(i=0;i<16;i++){
      this->item[i]=new Item;
      this->item[i]->setPos(i/4*this->item[i]->boundingRect().width(),i%4*this->item[i]->boundingRect().height());//宽高,找坐标
      this->addItem(this->item[i]);
  }
  this->ptimer=new QTimer;  //定时器
  connect(this->ptimer,SIGNAL(timeout()),this,SLOT(showMouse()));
  this->ptimer->start(500);
}
void scene::showMouse()
{
    //随机一个数0-15
    //1-3
    int count=1;   //弹出一只老鼠
    int i=0;
    //老鼠弹出后，恢复草坪图片
    for(i=0;i<16;i++){
        this->item[i]->setPic(":/bg/qt.picture/bg1.jpg");
    }
    //随机坑里弹出老鼠
    for(i=0;i<count;i++){
        int index=rand()%16;
        this->item[index]->setPic(":/bg/qt.picture/daqian.jpg");
    }

}
